package com.geostar.constructionland.analyse.service.analyseresult.impl;

import com.geostar.constructionland.analyse.service.analyseresult.*;
import com.geostar.constructionland.common.dao.YzGeoJsonDao;
import com.geostar.constructionland.analyse.entity.alyresult.tzhdlgdfx.*;
import com.geostar.constructionland.analyse.entity.statistics.SticDlfxTzh;
import com.geostar.constructionland.analyse.mapper.statistics.SticDlfxTzhMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;

/**
 * @author yelll
 * @since 2020-6-11 14:39
 **/
@Service
public class TzhDlGdFxServiceImpl implements TzhDlGdFxService {
    @Autowired
    AlyResultZdxxService alyResultZdxxService;
    @Autowired
    AlyResultQlxxService alyResultQlxxService;
    @Autowired
    AlyResultDlfxService alyResultDlfxService;
    @Autowired
    AlyResultXzdwService alyResultXzdwService;
    @Autowired
    AlyResultGdzldbService gdzldbService;
    @Autowired
    SticDlfxTzhMapper sticDlfxTzhMapper;
    @Autowired
    SticDlfxTzhService sticDlfxTzhService;
    @Override
    public void saveAlyResultZdxxs(List<AlyResultZdxx> zdxxList) {
        /**宗地信息调整为批量插入**/
        alyResultZdxxService.saveBatch(zdxxList);
    }

    @Override
    public void saveAlyResultQlxxs(List<AlyResultQlxx> qlxxList) {
        /**权利信息调整为批量插入**/
        alyResultQlxxService.saveBatch(qlxxList);
    }

    @Autowired
    YzGeoJsonDao yzGeoJsonDao;
    @Override
    public void saveAlyResultDlfx(List<AlyResultDlfx> dlfxList) {
        for(AlyResultDlfx alyResultDlfx : dlfxList){
            if(alyResultDlfx.getYzGeoJson()!=null) {
                /**保存mongodb数据**/
                yzGeoJsonDao.saveYzGeoJson(alyResultDlfx.getYzGeoJson());
            }
        }
        alyResultDlfxService.saveBatch(dlfxList);
    }

    @Override
    public void saveAlyResultXzdws(List<AlyResultXzdw> xzdwList) {
        alyResultXzdwService.saveBatch(xzdwList);
    }

    @Override
    public void saveAlyResultGdZldbs(List<AlyResultGdZlDb> gdZlDbList) {
        gdzldbService.saveBatch(gdZlDbList);
    }

    @Override
    public List<SticDlfxTzh> getSticDlFxTzh(String fxbs) {
        return sticDlfxTzhMapper.getSticDlFxTzh(fxbs);
    }

    @Override
    public void saveSticDlfxTzh(List<SticDlfxTzh> sticDlfxTzhs) {
        for(SticDlfxTzh sticDlfxTzh : sticDlfxTzhs){
            sticDlfxTzh.setZymjYs(sticDlfxTzh.getZymj());
            sticDlfxTzh.setZymj(new BigDecimal(sticDlfxTzh.getZymj()).setScale(0,BigDecimal.ROUND_HALF_UP).doubleValue());
            sticDlfxTzh.setFxid(UUID.randomUUID().toString().replaceAll("-",""));
        }
        sticDlfxTzhService.saveBatch(sticDlfxTzhs);
    }

    @Override
    public double getTotalZymjScaled(String fxbs) {
        return sticDlfxTzhMapper.getTotalZymjScaled(fxbs);
    }

    @Override
    public double getTotalDkmjYs(String ywid) {
        return sticDlfxTzhMapper.getTotalDkmjYs(ywid);
    }

    @Override
    public void saveGdZlfxTj(String fxbs) {
        sticDlfxTzhMapper.saveGdZlFxTj(fxbs);
    }
}
